import pygame
from random import randint, random


class Hanbao(pygame.sprite.Sprite):
    energy = 1
    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.transform.scale(pygame.image.load('images/hanbao.png').convert_alpha(), (50,40))

        self.destroy_images = []
        # self.destroy_images.extend([
        #     pygame.image.load('image/enemy1_down1.png').convert_alpha(),
        #     pygame.image.load('image/enemy1_down2.png').convert_alpha(),
        #     pygame.image.load('image/enemy1_down3.png').convert_alpha(),
        #     pygame.image.load('image/enemy1_down4.png').convert_alpha(),
        # ])
        self.rect = self.image.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.speed = 7
        self.active = True
        self.size = randint(10, 15)
        self.rect.left, self.rect.top = randint(0, self.width - self.rect.width), randint(-5 * self.height, 0)
        self.mask = pygame.mask.from_surface(self.image)
        self.energy = Hanbao.energy

    def reset(self):
        self.active = True
        self.rect.left, self.rect.top = randint(0, self.width - self.rect.width), randint(-5 * self.height, 0)

    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.reset()

